<template>
  <div>
    <template v-for="(item,index) in numPages">
      <notation
        :url="pdfSrcObj"
        :fileType="fileType"
        :pageIndex="item"
        :key="'notation' + index"
        :ref="'notation' + index"
        :allowMark="activeClass"
        :markS="totalMarkS[index]"
        :createItem="position[index]"
        @cancelMark="cancelMark"
        @change="handChange"
        @success="success"
      />
    </template>
  </div>
</template>

<script>
import notation from "@/components/pdf/notation";
import CMapReaderFactory from 'vue-pdf/src/CMapReaderFactory.js'
import pdf from "vue-pdf";
export default {
  name: "pdf",
  data(){
    return {
      pdfSrcObj: '',
      fileType: 'pdf',
      totalMarkS: [], // 所有备注和图片
      numPages: 0, // pdf页码
      activeClass: false, // 是否可以添加备注
      position: [],
    }
  },
  comments: {
    notation
  },
  created() {
    this.fileType = 'pdf'
    this.pdfSrcObj = pdf.createLoadingTask({ url: "http://39.101.169.161:9000/mat-materials/mat-files/2022-09-19/6327c82b5e8ced1d913f3482/4.pdf?response-content-type=application%2Foctet-stream&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20221221%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221221T055829Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=230baa2b7238eac54d3d71d3c32da91512c22b9d0a27916eee06ee0d3b5d02e6", CMapReaderFactory })
    this.pdfSrcObj.promise.then((pdf) => {
      this.numPages = pdf.numPages
      for (let i = 0; i < pdf.numPages; i++) {
        this.totalMarkS.push([])
        this.position.push([])
      }
    })
  },
  methods: {
    // 加载成功
    success(num) {
      this.numPage = num
    },
    cancelMark() {
      this.activeClass = false
    },
    handChange(){
      this.operation = true
    },
  }
}
</script>

<style scoped>

</style>
